{% extends "../layouts/admin.html" %} {% block content %}

<header class="header navbar bg-white shadow">

	<div class="pull-right offscreen-right">
		<button class="btn btn-primary navbar-btn" onclick="sublime.toggleFilter('.cd-panel')"><i
          class="fa fa-sliders"></i> 筛选
      </button>
	</div>
</header>
<div class=panel-body style="padding-top: 50px;">
	<div class="table-responsive no-border">
		<input id="unitid" type="hidden">
		<table class="table table-bordered table-striped mg-t datatable">
			<thead>
				<tr>
					<th>ID</th>
					<th>用户ID</th>
					<th>关联订单</th>
					<th>订单号</th>
					<th>退款金额</th>
					<th>退款渠道</th>
					<th>退款户名</th>
					<th>退款账号</th>
					<th>退款状态</th>
					<th>审核备注</th>
					<th>创建时间</th>
					<th>处理时间</th>
					<th>操作</th>

		</table>
	</div>
</div>
<div class="cd-panel from-right">
	<header class="cd-panel-header">
		<h4>高级筛选</h4>
	</header>
	<div class="cd-panel-container">
		<div class="cd-panel-content shadow">
			<div class="form-group">
				<label for="userid">用户ID</label>
				<input type="text" id="userid" name="userid" onclick="this.value=''" class="form-control" placeholder="用户ID">
			</div>

			<button id="searchBtn" type="button" class="btn btn-default">查询</button>
		</div>
	</div>
</div>

<div id="dialogDeal" class="modal fade bs-modal-sm" tabindex="-2" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h4 class="modal-title">退款处理</h4>
			</div>
			<div class="modal-body">
				<div class="row">
					<div class="col-xs-12">
						您确定要<span id="dealIdea">同意</span>退款吗？ <br/>
						
						<textarea name="deal_idea" id="deal_idea" class="form-control mt10" placeholder="审核备注"></textarea>
					</div>
				</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
				<button id="ok" type="button" class="btn btn-primary" data-loading-text="正在处理...">确 定</button>
			</div>
		</div>
	</div>
</div>
<div id="dialogDetail" class="modal fade bs-modal" tabindex="-3" role="dialog" aria-hidden="true">
	<div class="modal-dialog"  style="width:800px">
		<div class="modal-content">
		</div>
	</div>
</div>
<script language="JavaScript">
	function initDatatable() {
		datatable = $('.datatable').DataTable({
				"dom": '<"toolbar">frtip',
				"searching": false,
				"processing": false,
				"serverSide": true,
				"select": true,
				"ordering": true,
				"language": {
					"url": "/assets/plugins/datatables/cn.json"
				},
				"preDrawCallback": function() {
					sublime.showLoadingbar($(".main-content"));
				},
				"drawCallback": function() {
					sublime.closeLoadingbar($(".main-content"));
				},
				"ajax": {
					"url": "/store/refund/index",
					"type": "post",
					"data": function(d) {
						d.userid = $('#userid').val();

					}
				},
				"order": [
					[0, 'desc']
				],
				"columns": [
				
				
				
					

					{
						"data": "id",
						"bSortable": true
					}, {
						"data": "user_id",
						"bSortable": true
					},
					{
						"data": "order_id",
						"bSortable": true
					},
					{
						"data": "order_no",
						"bSortable": false
					},
					{
						"data": "amount",
						"bSortable": true
					},
					{
						"data": "account_bank",
						"bSortable": true
					},
					{
						"data": "account_name",
						"bSortable": true
					},
					{
						"data": "account",
						"bSortable": true
					},
					{
						"data": "status",
						"bSortable": true
					},
					{
						"data": "deal_idea",
						"bSortable": true
					},
					{
						"data": "create_time",
						"bSortable": true
					},
					{
						"data": "deal_time",
						"bSortable": true
					}

				],
				"columnDefs": [
				{
					"render": function(data, type, row) {
						var refundStatus = {{config.setup.refundStatus | stringify | safe}};

						return refundStatus[data];
					},
					"targets": 8
				},
				{
					"render": function(data, type, row) {
						return sublime.datetime(data);
					},
					"targets": 10
				},
				{
					"render": function(data, type, row) {
						return sublime.datetime(data);
					},
					"targets": 11
				},
				
				{
			          "render": function (data, type, row) {
			          	var m = ""
			          	
			          	
			          	if(row.status == 0){
			          		m +=  '<li><a onclick="deal(' + row.id + ',1)">同意</a></li>' ;
			          		m +=  '<li><a onclick="deal(' + row.id + ',-2)">拒绝</a></li>' ;
			          		
			          	}
			          	
			            return '<div class="btn-group"><button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">' +
			              ' <i class="ti-settings"></i> <span class="ti-angle-down"></span></button><ul class="dropdown-menu" role="menu">' +
			              '<li><a href="/store/refund/detail?id=' + row.id + '"    data-toggle="modal" data-target="#dialogDetail">详情</a></li>' +
			             m+
			              '</ul></div>';
			          },
			          "targets": 12
			    }
			]
		});

	$("#searchBtn").on('click', function() {
		datatable.ajax.reload();
	});
	}

	$(function() {
		initDatatable();
		$("#dialogDetail").on("hidden.bs.modal", function() {
			$(this).removeData("bs.modal");
		});
	});
	
	function deal(id,status) {
    var dialog = $("#dialogDeal");
    if(status == 1){
    	dialog.find("#dealIdea").text("同意");
    }else{
    	dialog.find("#dealIdea").text("拒绝");
    }
    
    dialog.modal("show");
    dialog.find("#ok").unbind("click");
    dialog.find("#ok").bind("click", function (event) {
      var btn = $(this);
      btn.button("loading");
      var deal_idea = dialog.find("#deal_idea").val();
      $.post("/store/refund/deal", {id: id,status:status,deal_idea:deal_idea}, function (data) {
        if (data.errno == 0) {
          datatable.ajax.reload(null,false);
        } else {
          Toast.error(data.errmsg);
        }
        //重置按钮状态，关闭提示框
        btn.button("reset");
        dialog.modal("hide");
      }, "json");
    });
  }
</script>
{% endblock %}